//全选
$(function(){
    $("#zcheckbox").change(function(){//判断全选框的改变
        var flage =$(this).is(":checked");//全选选中为true，否则为false
        $("input[type=checkbox]").each(function(){
            $(this).prop("checked",flage);
        })
    })
});

//获取勾选的行数据的id并将其用,拼接成字符串
function getIds() {
    var str = '';
    for(var i = 0; i < document.getElementsByName('ids').length; i++) {
        if(document.getElementsByName('ids')[i].checked) {
            if(str == '') {
                str += document.getElementsByName('ids')[i].value;
            } else {
                str += ',' + document.getElementsByName('ids')[i].value;
            }
        }
    }
    return str;
}

//如果没有选择数据提示信息
function batchErrorMessage() {
    bootbox.dialog({
        message: "<span class='bigger-110'>您没有选择任何内容!</span>",
        buttons:{
            "button":{
                "label":"确定",
                "className":"btn-sm btn-success"
            }
        }
    });
    $("#zcheckbox").tips({
        side:3,
        msg:'点这里全选',
        bg:'#AE81FF',
        time:8
    });
}

//检索
function searchs(){
    top.jzts();
    $("#form").submit();
}

//详情
function detail(id) {
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title = "详情";
    diag.URL = path + '/admin/articleChargePricingConfig/detailPage?id='+ id;
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){ //关闭事件
        diag.close();
    };
    diag.show();
}

//验证是否允许新增，如果所有的用户等级都配置了文章收费定价配置就不再允许新增数据
function validateAdd() {
    var flag = false;
    $.ajax({
        url : path + "/admin/articleChargePricingConfig/validateAdd",
        type : "post",
        async : false,
        dataType : "json",
        success : function (data) {
            //code等于200表示所有的用户等级都配置了文章收费定价配置，不再允许新增
            if (data.code == 200) {
                flag = true;
            }
        }
    });
    return flag;
}

//新增
function add(currentPage){
    var flag = validateAdd();
    if (flag) {
        bootbox.alert({
            message: '所有的用户等级都配置了文章收费定价配置，不再允许新增数据！',
            buttons: {
                ok: {
                    label: '我知道了'
                }
            }
        });
        return false;
    }
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="新增";
    diag.URL = path + '/admin/articleChargePricingConfig/addPage';
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//编辑
function edit(id, currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="编辑";
    diag.URL = path + '/admin/articleChargePricingConfig/editPage?id=' + id;
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//批量修改
function editBatch(currentPage) {
    bootbox.confirm("确定要批量修改选中的数据吗?", function(result) {
        if (result) {
            var ids = getIds();
            if(ids==''){
                batchErrorMessage();
            }else {
                top.jzts();
                var diag = new top.Dialog();
                diag.Drag = true;
                diag.Title = "批量修改";
                diag.URL = path + '/admin/articleChargePricingConfig/editBatchPage?ids=' + ids;
                diag.Width = 1050;
                diag.Height = 580;
                diag.CancelEvent = function () {//关闭事件
                    if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                        if (currentPage == '0') {
                            top.jzts();
                            setTimeout("self.location=self.location", 100);
                        } else {
                            nextPage(currentPage);
                        }
                    }
                    diag.close();
                };
                diag.show();
            }
        }
    });
}
